perf: optimize update_plugin function #1665
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the performance of the
update_plugin
function by only contacting remote if/when needed.It does so by making two main changes:
ls-remote
when the third parameter to the function is not provided, as before it was always run and its result was ignored if the third parameter was there;fetch
remote unless needed, i.e. not fetching if the providedgitref
is a commit and is already available locally.This gives a big performance boost, especially when on a slow internet connection, and removes the dependency on remote when it's not needed. For example, the change is very noticeable when re-running
add-all
while using asdf-plugin-manager.Benchmarks
With the original implementation:
asdf plugin update <plugin-name>
: ≈3.5s ← remote contacted twiceasdf plugin update <plugin-name> <branch>
: ≈3.5s ← remote contacted twiceasdf plugin update <plugin-name> <new gitref>
: ≈3.5s ← remote contacted twiceasdf plugin update <plugin-name> <existing gitref>
: ≈3.5s ← remote contacted twiceWith these changes:
asdf plugin update <plugin-name>
: ≈3.5s ← remote contacted twiceasdf plugin update <plugin-name> <branch>
: ≈1.7s ← remote contacted onceasdf plugin update <plugin-name> <new gitref>
: ≈1.7s ← remote contacted onceasdf plugin update <plugin-name> <existing gitref>
: ≈0.1s ← remote not contacted at allNote: these benchmarks are from my machine with my internet connection. Results may vary a lot depending on the internet connection of the device running them.